package org.aphelie.chronicle.character.ui.editors;


import org.aphelie.chronicle.ArcSheet;
import org.aphelie.chronicle.character.Traits;
import org.aphelie.chronicle.ui.editors.ArcSheetEditor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.ui.util.EditUIUtil;
import org.eclipse.ui.PartInitException;

public class CharacterEditor extends ArcSheetEditor {
	
	
    protected ArcSheet sheet;

    public ArcSheet getSheet() {
            if (sheet == null) {
                    createSheet();
            }
            return sheet;
    }

    protected void createSheet() {
            sheet = (ArcSheet) getResource().getContents().get(0);
            /*
            Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
            if (diagnostic.getSeverity() != Diagnostic.OK) {
                    resourceToDiagnosticMap.put(resource,  analyzeResourceProblems(resource, exception));
            }
            editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter);
            */
    }
    
    @SuppressWarnings("unused")
	public Resource getResource() {
        URI resourceURI = EditUIUtil.getURI(getEditorInput());
        Exception exception = null;
        Resource resource = null;
        try {
                // Load the resource through the editing domain
                resource = editingDomain.getResourceSet().getResource(resourceURI, true);
        } catch (Exception e) {
                exception = e;
                resource.getResourceSet().getResource(resourceURI, false);
        }
        return resource;
}



	public CharacterEditor() {
		super();
	}

	@Override
	protected void addPages() {
		try {
			addPage(new TraitsPage(this, (Traits) getEditedSheet()));
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return false;
	}

}
